IdentityJwtAuthProvider<TUser, TRole>
Converts an MVC JwtBearer Cookie into a ServiceStack Session
Assembly: ServiceStack.Extensions.dll
View Source
public class IdentityJwtAuthProvider<TUser, TRole> : AuthProvider, IAuthProvider, IAuthPlugin, IIdentityJwtAuthProvider, IAuthWithRequest, IAuthResponseFilter where TUser : IdentityUser where TRole : IdentityRole
Properties
Type
View Source
public override string Type { get; }
DefaultIssuer
Default Issuer to use if unspecified
View Source
public string DefaultIssuer { get; set; }
HashAlgorithm
Which Hash Algorithm should be used to sign the JWT Token. (default HS256)
View Source
public string HashAlgorithm { get; set; }
AuthenticationScheme
Which JWT Authentication Scheme configuration to use (default Bearer)
View Source
public string AuthenticationScheme { get; }
Options
The JWT Bearer Options to use (default populated from AuthenticationScheme JwtBearerOptions)
View Source
public JwtBearerOptions Options { get; set; }
TokenValidationParameters
The JwtBearerOptions TokenValidationParameters short-hand
View Source
public TokenValidationParameters TokenValidationParameters { get; set; }
ExpireTokensIn
How long should JWT Tokens be valid for. (default 14 days)
View Source
public TimeSpan ExpireTokensIn { get; set; }
ExpireRefreshTokensIn
How long should JWT Refresh Tokens be valid for. (default 365 days)
View Source
public TimeSpan ExpireRefreshTokensIn { get; set; }
ExpireTokensInDays
Convenient overload to initialize ExpireTokensIn with an Integer
View Source
public int ExpireTokensInDays { set; }
RequireSecureConnection
Whether to only allow access via Bearer Token from a secure connection (default true)
View Source
public bool RequireSecureConnection { get; set; }
ResolveJwtId
Change resolution for resolving unique jti id for Access Tokens
View Source
public Func<IRequest, string>? ResolveJwtId { get; set; }
ResolveRefreshJwtId
Change resolution for resolving unique jti id for Refresh Tokens
View Source
public Func<IRequest, string>? ResolveRefreshJwtId { get; set; }
Audience
Return Valid Audiences in comma-delimited string
View Source
public string Audience { get; }
MapIdentityUserToClaims
View Source
public List<(string fieldName, string claimType)> MapIdentityUserToClaims { get; set; }
NameClaimFieldNames
View Source
public List<string> NameClaimFieldNames { get; set; }
OnTokenCreated
Customize which claims are included in the JWT Token
View Source
public Action<IRequest, TUser, List<Claim>>? OnTokenCreated { get; set; }
OnRefreshTokenCreated
Customize which claims are included in the JWT Refresh Token
View Source
public Action<IRequest, string, List<Claim>>? OnRefreshTokenCreated { get; set; }
OnSessionCreated
Run custom filter after session is restored from a JWT Token
View Source
public Action<IAuthSession, List<Claim>, IRequest>? OnSessionCreated { get; set; }
Inherited Properties
AccountLockedValidator
View Source
public Func<IAuthRepository, IUserAuth, IAuthTokens, bool> AccountLockedValidator { get; set; }
AuthEvents
View Source
public IAuthEvents AuthEvents { get; }
AuthRealm
View Source
public string AuthRealm { get; set; }
CallbackUrl
View Source
public string CallbackUrl { get; set; }
CustomValidationFilter
View Source
public Func<AuthContext, IHttpResult> CustomValidationFilter { get; set; }
ExcludeAuthInfoItems
View Source
public HashSet<string> ExcludeAuthInfoItems { get; set; }
FormLayout
View Source
public List<InputInfo> FormLayout { get; set; }
Icon
View Source
public ImageInfo Icon { get; set; }
Label
View Source
public string Label { get; set; }
LoadUserAuthFilter
View Source
public Action<AuthUserSession, IAuthTokens, Dictionary<string, string>> LoadUserAuthFilter { get; set; }
LoadUserAuthInfoFilterAsync
View Source
public Func<AuthUserSession, IAuthTokens, Dictionary<string, string>, CancellationToken, Task> LoadUserAuthInfoFilterAsync { get; set; }
Meta
View Source
public virtual Dictionary<string, string> Meta { get; }
NavItem
View Source
public NavItem NavItem { get; set; }
PersistSession
View Source
public bool PersistSession { get; set; }
Provider
View Source
public string Provider { get; set; }
RedirectUrl
View Source
public string RedirectUrl { get; set; }
RestoreSessionFromState
View Source
public bool? RestoreSessionFromState { get; set; }
SaveExtendedUserInfo
View Source
public bool SaveExtendedUserInfo { get; set; }
SessionExpiry
View Source
public TimeSpan? SessionExpiry { get; set; }
Sort
View Source
public int Sort { get; set; }
Type
View Source
public virtual string Type { get; }
Fields
Name
View Source
public const string Name = null
Realm
View Source
public const string Realm = null
Methods
NextJwtId()
Get the next AutoId for usage in jti JWT Access Tokens
View Source
public string NextJwtId()
Returns
System.String
LastJwtId()
Get the last jti AutoId generated
View Source
public string LastJwtId()
Returns
System.String
NextRefreshJwtId()
Get the next AutoId for usage in jti JWT Refresh Tokens
View Source
public string NextRefreshJwtId()
Returns
System.String
LastRefreshJwtId()
View Source
public string LastRefreshJwtId()
Returns
System.String
Register(IAppHost, AuthFeature)
View Source
public override void Register(IAppHost appHost, AuthFeature feature)
Parameters
Type | Name |
---|---|
ServiceStack.IAppHost | appHost |
ServiceStack.AuthFeature | feature |
AuthenticateResponseDecorator(AuthFilterContext)
View Source
public object AuthenticateResponseDecorator(AuthFilterContext ctx)
Returns
System.Object
Parameters
Type | Name |
---|---|
ServiceStack.Auth.AuthFilterContext | ctx |
RegisterResponseDecorator(RegisterFilterContext)
View Source
public object RegisterResponseDecorator(RegisterFilterContext ctx)
Returns
System.Object
Parameters
Type | Name |
---|---|
ServiceStack.Auth.RegisterFilterContext | ctx |
IsAuthorized(IAuthSession, IAuthTokens, Authenticate)
View Source
public override bool IsAuthorized(IAuthSession session, IAuthTokens tokens, Authenticate request = null)
Returns
System.Boolean
Parameters
Type | Name |
---|---|
ServiceStack.Auth.IAuthSession | session |
ServiceStack.Auth.IAuthTokens | tokens |
ServiceStack.Authenticate | request |
AuthenticateAsync(IServiceBase, IAuthSession, Authenticate, CancellationToken)
View Source
public override Task<object> AuthenticateAsync(IServiceBase authService, IAuthSession session, Authenticate request, CancellationToken token = null)
Returns
Task<System.Object>
Parameters
Type | Name |
---|---|
ServiceStack.IServiceBase | authService |
ServiceStack.Auth.IAuthSession | session |
ServiceStack.Authenticate | request |
CancellationToken | token |
PreAuthenticateAsync(IRequest, IResponse)
Populate ServiceStack Session from JWT
View Source
public Task PreAuthenticateAsync(IRequest req, IResponse res)
Returns
Task
Parameters
Type | Name |
---|---|
ServiceStack.Web.IRequest | req |
ServiceStack.Web.IResponse | res |
CreateSessionFromClaims(IRequest, List<Claim>)
View Source
public virtual IAuthSession CreateSessionFromClaims(IRequest req, List<Claim> claims)
Returns
ServiceStack.Auth.IAuthSession
Parameters
Type | Name |
---|---|
ServiceStack.Web.IRequest | req |
List<Claim> | claims |
EnableRefreshToken()
View Source
protected virtual bool EnableRefreshToken()
Returns
System.Boolean
GetUserAndRolesAsync(IServiceBase, String)
View Source
public async Task<(TUser, IEnumerable<string>)> GetUserAndRolesAsync(IServiceBase service, string email)
Returns
Task<System.ValueTuple<<TUser>,IEnumerable<System.String>>>
Parameters
Type | Name |
---|---|
ServiceStack.IServiceBase | service |
System.String |
ExecuteAsync(AuthFilterContext)
View Source
public virtual async Task ExecuteAsync(AuthFilterContext authContext)
Returns
Task
Parameters
Type | Name |
---|---|
ServiceStack.Auth.AuthFilterContext | authContext |
CreateJwtBearerToken(IRequest, TUser, Nullable<IEnumerable<String>>)
View Source
protected string? CreateJwtBearerToken(IRequest req, TUser user, IEnumerable<string>? roles = null)
Returns
System.Nullable<System.String>
Parameters
Type | Name |
---|---|
ServiceStack.Web.IRequest | req |
<TUser> | user |
System.Nullable<IEnumerable<System.String>> | roles |
CreateJwtRefreshToken(IRequest, String, TimeSpan)
View Source
protected virtual string? CreateJwtRefreshToken(IRequest req, string userId, TimeSpan expireRefreshTokensIn)
Returns
System.Nullable<System.String>
Parameters
Type | Name |
---|---|
ServiceStack.Web.IRequest | req |
System.String | userId |
TimeSpan | expireRefreshTokensIn |
ResultFilterAsync(AuthResultContext, CancellationToken)
View Source
public async Task ResultFilterAsync(AuthResultContext authContext, CancellationToken token = null)
Returns
Task
Parameters
Type | Name |
---|---|
ServiceStack.Auth.AuthResultContext | authContext |
CancellationToken | token |
Inherited Methods
AuthenticateAsync(IServiceBase, IAuthSession, Authenticate, CancellationToken)
View Source
public abstract Task<object> AuthenticateAsync(IServiceBase authService, IAuthSession session, Authenticate request, CancellationToken token = default(CancellationToken))
Returns
System.Threading.Tasks.Task<System.Object>
Parameters
Type | Name |
---|---|
ServiceStack.IServiceBase | authService |
ServiceStack.Auth.IAuthSession | session |
ServiceStack.Authenticate | request |
System.Threading.CancellationToken | token |
ConvertToClientError(Object, Boolean)
View Source
protected virtual object ConvertToClientError(object failedResult, bool isHtml)
Returns
System.Object
Parameters
Type | Name |
---|---|
System.Object | failedResult |
System.Boolean | isHtml |
CreateAuthContext(IServiceBase, IAuthSession, IAuthTokens)
View Source
protected virtual AuthContext CreateAuthContext(IServiceBase authService = null, IAuthSession session = null, IAuthTokens tokens = null)
Returns
Parameters
Type | Name |
---|---|
ServiceStack.IServiceBase | authService |
ServiceStack.Auth.IAuthSession | session |
ServiceStack.Auth.IAuthTokens | tokens |
CreateOrMergeAuthSession(IAuthSession, IAuthTokens)
View Source
public virtual string CreateOrMergeAuthSession(IAuthSession session, IAuthTokens tokens)
Returns
System.String
Parameters
Type | Name |
---|---|
ServiceStack.Auth.IAuthSession | session |
ServiceStack.Auth.IAuthTokens | tokens |
EmailAlreadyExistsAsync(IAuthRepositoryAsync, IUserAuth, IAuthTokens, CancellationToken)
View Source
protected virtual async Task<bool> EmailAlreadyExistsAsync(IAuthRepositoryAsync authRepo, IUserAuth userAuth, IAuthTokens tokens = null, CancellationToken token = default(CancellationToken))
Returns
System.Threading.Tasks.Task<System.Boolean>
Parameters
Type | Name |
---|---|
ServiceStack.Auth.IAuthRepositoryAsync | authRepo |
ServiceStack.Auth.IUserAuth | userAuth |
ServiceStack.Auth.IAuthTokens | tokens |
System.Threading.CancellationToken | token |
FallbackConfig(String)
Allows specifying a global fallback config that if exists is formatted with the Provider as the first arg. E.g. this appSetting with the TwitterAuthProvider: oauth.CallbackUrl="http://localhost:11001/auth/{0}" Would result in: oauth.CallbackUrl="http://localhost:11001/auth/twitter"
View Source
protected string FallbackConfig(string fallback)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | fallback |
GetAuthRedirectUrl(IServiceBase, IAuthSession)
View Source
protected virtual string GetAuthRedirectUrl(IServiceBase authService, IAuthSession session)
Returns
System.String
Parameters
Type | Name |
---|---|
ServiceStack.IServiceBase | authService |
ServiceStack.Auth.IAuthSession | session |
GetAuthRepository(IRequest)
View Source
protected virtual IAuthRepository GetAuthRepository(IRequest req)
Returns
ServiceStack.Auth.IAuthRepository
Parameters
Type | Name |
---|---|
ServiceStack.Web.IRequest | req |
GetAuthRepositoryAsync(IRequest)
View Source
protected virtual IAuthRepositoryAsync GetAuthRepositoryAsync(IRequest req)
Returns
ServiceStack.Auth.IAuthRepositoryAsync
Parameters
Type | Name |
---|---|
ServiceStack.Web.IRequest | req |
GetReferrerUrl(IServiceBase, IAuthSession, Authenticate)
View Source
protected virtual string GetReferrerUrl(IServiceBase authService, IAuthSession session, Authenticate request = null)
Returns
System.String
Parameters
Type | Name |
---|---|
ServiceStack.IServiceBase | authService |
ServiceStack.Auth.IAuthSession | session |
ServiceStack.Authenticate | request |
GetUserAuthRepositoryAsync(IRequest)
View Source
public IUserAuthRepositoryAsync GetUserAuthRepositoryAsync(IRequest request)
Returns
ServiceStack.Auth.IUserAuthRepositoryAsync
Parameters
Type | Name |
---|---|
ServiceStack.Web.IRequest | request |
IsAccountLockedAsync(IAuthRepositoryAsync, IUserAuth, IAuthTokens, CancellationToken)
View Source
public virtual Task<bool> IsAccountLockedAsync(IAuthRepositoryAsync authRepoAsync, IUserAuth userAuth, IAuthTokens tokens = null, CancellationToken token = default(CancellationToken))
Returns
System.Threading.Tasks.Task<System.Boolean>
Parameters
Type | Name |
---|---|
ServiceStack.Auth.IAuthRepositoryAsync | authRepoAsync |
ServiceStack.Auth.IUserAuth | userAuth |
ServiceStack.Auth.IAuthTokens | tokens |
System.Threading.CancellationToken | token |
IsAuthorized(IAuthSession, IAuthTokens, Authenticate)
View Source
public abstract bool IsAuthorized(IAuthSession session, IAuthTokens tokens, Authenticate request = null)
Returns
System.Boolean
Parameters
Type | Name |
---|---|
ServiceStack.Auth.IAuthSession | session |
ServiceStack.Auth.IAuthTokens | tokens |
ServiceStack.Authenticate | request |
LoadUserAuthInfo(AuthUserSession, IAuthTokens, Dictionary<String, String>)
View Source
[Obsolete("Use LoadUserAuthInfoAsync")]
protected void LoadUserAuthInfo(AuthUserSession userSession, IAuthTokens tokens, Dictionary<string, string> authInfo)
Parameters
Type | Name |
---|---|
ServiceStack.AuthUserSession | userSession |
ServiceStack.Auth.IAuthTokens | tokens |
System.Collections.Generic.Dictionary<System.String,System.String> | authInfo |
LoadUserAuthInfoAsync(AuthUserSession, IAuthTokens, Dictionary<String, String>, CancellationToken)
View Source
protected virtual Task LoadUserAuthInfoAsync(AuthUserSession userSession, IAuthTokens tokens, Dictionary<string, string> authInfo, CancellationToken token = default(CancellationToken))
Returns
System.Threading.Tasks.Task
Parameters
Type | Name |
---|---|
ServiceStack.AuthUserSession | userSession |
ServiceStack.Auth.IAuthTokens | tokens |
System.Collections.Generic.Dictionary<System.String,System.String> | authInfo |
System.Threading.CancellationToken | token |
LoginMatchesSession(IAuthSession, String)
View Source
protected static bool LoginMatchesSession(IAuthSession session, string userName)
Returns
System.Boolean
Parameters
Type | Name |
---|---|
ServiceStack.Auth.IAuthSession | session |
System.String | userName |
LogoutAsync(IServiceBase, Authenticate, CancellationToken)
Remove the Users Session
View Source
public virtual async Task<object> LogoutAsync(IServiceBase service, Authenticate request, CancellationToken token = default(CancellationToken))
Returns
System.Threading.Tasks.Task<System.Object>
Parameters
Type | Name |
---|---|
ServiceStack.IServiceBase | service |
ServiceStack.Authenticate | request |
System.Threading.CancellationToken | token |
OnAuthenticatedAsync(IServiceBase, IAuthSession, IAuthTokens, Dictionary<String, String>, CancellationToken)
View Source
public virtual async Task<IHttpResult> OnAuthenticatedAsync(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo, CancellationToken token = default(CancellationToken))
Returns
System.Threading.Tasks.Task<ServiceStack.Web.IHttpResult>
Parameters
Type | Name |
---|---|
ServiceStack.IServiceBase | authService |
ServiceStack.Auth.IAuthSession | session |
ServiceStack.Auth.IAuthTokens | tokens |
System.Collections.Generic.Dictionary<System.String,System.String> | authInfo |
System.Threading.CancellationToken | token |
OnFailedAuthentication(IAuthSession, IRequest, IResponse)
View Source
public virtual Task OnFailedAuthentication(IAuthSession session, IRequest httpReq, IResponse httpRes)
Returns
System.Threading.Tasks.Task
Parameters
Type | Name |
---|---|
ServiceStack.Auth.IAuthSession | session |
ServiceStack.Web.IRequest | httpReq |
ServiceStack.Web.IResponse | httpRes |
Register(IAppHost, AuthFeature)
View Source
public virtual void Register(IAppHost appHost, AuthFeature feature)
Parameters
Type | Name |
---|---|
ServiceStack.IAppHost | appHost |
ServiceStack.AuthFeature | feature |
UrlFilter(AuthContext, String)
View Source
public static string UrlFilter(AuthContext provider, string url)
Returns
System.String
Parameters
Type | Name |
---|---|
ServiceStack.Auth.AuthContext | provider |
System.String | url |
UserNameAlreadyExistsAsync(IAuthRepositoryAsync, IUserAuth, IAuthTokens, CancellationToken)
View Source
protected virtual async Task<bool> UserNameAlreadyExistsAsync(IAuthRepositoryAsync authRepo, IUserAuth userAuth, IAuthTokens tokens = null, CancellationToken token = default(CancellationToken))
Returns
System.Threading.Tasks.Task<System.Boolean>
Parameters
Type | Name |
---|---|
ServiceStack.Auth.IAuthRepositoryAsync | authRepo |
ServiceStack.Auth.IUserAuth | userAuth |
ServiceStack.Auth.IAuthTokens | tokens |
System.Threading.CancellationToken | token |
ValidateAccountAsync(IServiceBase, IAuthRepositoryAsync, IAuthSession, IAuthTokens, CancellationToken)
View Source
protected virtual async Task<IHttpResult> ValidateAccountAsync(IServiceBase authService, IAuthRepositoryAsync authRepo, IAuthSession session, IAuthTokens tokens, CancellationToken token = default(CancellationToken))
Returns
System.Threading.Tasks.Task<ServiceStack.Web.IHttpResult>
Parameters
Type | Name |
---|---|
ServiceStack.IServiceBase | authService |
ServiceStack.Auth.IAuthRepositoryAsync | authRepo |
ServiceStack.Auth.IAuthSession | session |
ServiceStack.Auth.IAuthTokens | tokens |
System.Threading.CancellationToken | token |